#include<bits/stdc++.h>
using namespace std;
struct node
{
	int num,arr,length,pri;
	bool operator < (const node a)const
	{
		return pri==a.pri?arr>a.arr:pri<a.pri;
	}
};
priority_queue<node> q;
int main()
{
	int t1,t2,t3,t4,time=0;
	while(scanf("%d%d%d%d",&t1,&t2,&t3,&t4)==4)
	{
		while(!q.empty())
		{
			node a=q.top();
			int st=max(time,a.arr);
			if(st>t2)break;
			q.pop();
			if(t2<st+a.length)
			{
				q.push((node){a.num,a.arr,a.length-t2+st,a.pri});
				time=t2;
				break;
			}
			else
			{
				time=st+a.length;
				printf("%d %d\n",a.num,time);
			}
		}
		q.push((node){t1,t2,t3,t4});
	}
	while(!q.empty())
	{
		node a=q.top();
		q.pop();
		int st=max(time,a.arr);
		time=st+a.length;
		printf("%d %d\n",a.num,time);
	}
	return 0;
}
